package com.vates.vsp.practico.alumnos.business;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import com.vates.vsp.practico.alumnos.service.AlumnosService;
import com.vates.vsp.practico.alumnos.view.AlumnoView;
import com.vates.vsp.practico.alumnos.view.AlumnosView;
import com.vates.vsp.practico.commons.ListDataModel;
import com.vates.vsp.practico.commons.UseCaseMode;

/**
 * 
 * @author scerrato
 * @since 21/10/2010 Capa de Negocio
 * @lastmod scerrato 10/11/2010
 */
@ManagedBean(name = "alumnosListener")
@SessionScoped
public class AlumnosListener {

	@ManagedProperty(value = "#{alumnosView}")
	private AlumnosView alumnosView;
	@ManagedProperty(value = "#{alumnoView}")
	private AlumnoView alumnoView;
	@ManagedProperty(value = "#{alumnosService}")
	private AlumnosService alumnosService;

	public AlumnosView getAlumnosView() {
		return alumnosView;
	}

	public void setAlumnosView(AlumnosView alumnosView) {
		this.alumnosView = alumnosView;
	}

	public AlumnosService getAlumnosService() {
		return alumnosService;
	}

	public void setAlumnosService(AlumnosService alumnosService) {
		this.alumnosService = alumnosService;
	}

	public AlumnoView getAlumnoView() {
		return alumnoView;
	}

	public void setAlumnoView(AlumnoView alumnoView) {
		this.alumnoView = alumnoView;
	}

	public String mostrarAlumnos() {
		alumnosView.setUseCaseMode(UseCaseMode.CONSULTA);
		List<Alumnos> resultado = alumnosService.getAllAlumnos();
		alumnosView.setAlumnos(new ListDataModel<Alumnos>(resultado));
		return "alumnos";
	}


	public String registrarAsistencias() {
		alumnosView.setUseCaseMode(UseCaseMode.CONSULTA);
		List<Alumnos> resultado = alumnosService.getAllAlumnos();
		alumnosView.setAlumnos(new ListDataModel<Alumnos>(resultado));
		return "alumnos";
	}
	
	public String volver() {
		return "volver";
	}

	public String salir() {
		return "salir";
	}

	public String irNuevoAlumno() {
		alumnoView.setUseCaseMode(UseCaseMode.NUEVO);
		alumnoView.setAlumno(new Alumnos());
		return "irNuevoAlumno";
	}

	public String irVerAlumno() {
		alumnoView.setUseCaseMode(UseCaseMode.CONSULTA);
		alumnoView.setAlumno(alumnosView.getAlumnos().getRowData());
		return "irVerAlumno";
	}

	public String irEditarAlumno() {
		alumnoView.setUseCaseMode(UseCaseMode.MODIFICACION);
		alumnoView.setAlumno(alumnosView.getAlumnos().getRowData());
		return "irEditarAlumno";
	}

	public String irBorrarAlumno() {
		alumnoView.setUseCaseMode(UseCaseMode.ELIMINAR);
		alumnoView.setAlumno(alumnosView.getAlumnos().getRowData());
		return "irBorrarAlumno";
	}

}
